home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / qbnewsl / qbnws203 / mouse / mousetst.bas < prev   
BASIC Source File  |  1991-09-03  |  18KB  |  470 lines

  1.     DEFINT A-Z
  2.  
  3.     REM $INCLUDE: 'MOUSE.BI'  
  4.  
  5.     CLS
  6.     PRINT "A Microsoft compatible mouse driver ";
  7.     IF MouseInstalled% THEN
  8.         PRINT "IS installed."
  9.     ELSE
  10.         PRINT "IS NOT installed."
  11.         END
  12.     END IF
  13.  
  14.     PRINT "It is ";
  15.     IF NOT MouseAlreadyReset% THEN
  16.         PRINT "NOT ";
  17.     END IF
  18.     PRINT "already reset."
  19.  
  20.     'The following routine resets the mouse and returns the number of buttons.
  21.     Buttons% = MouseReset%
  22.     
  23.     'Get current mouse sensitivity settings
  24.     CALL MouseGetSensitivity(VertRatio%, HorizRatio%, DblSpd%)
  25.     
  26.     'Get mouse hardware and software information
  27.     CALL MouseGetInfo(MajorV%, MinorV%, MouseType%, Irq%)
  28.  
  29.     PRINT "The mouse has been initialized."
  30.     PRINT
  31.     PRINT "Mouse information:"
  32.     PRINT
  33.     PRINT "       Mouse Driver Version:";
  34.     PRINT USING "##.##"; MajorV% + MinorV% / 100
  35.     PRINT "                 Mouse Type: ";
  36.     SELECT CASE MouseType%
  37.         CASE 1
  38.             PRINT "Bus Mouse"
  39.         CASE 2
  40.             PRINT "Serial Mouse"
  41.         CASE 3
  42.             PRINT "InPort Mouse"
  43.         CASE 4
  44.             PRINT "PS/2 Mouse"
  45.         CASE 5
  46.             PRINT "HP Mouse"
  47.         CASE ELSE
  48.             PRINT "Beats the heck outta me!"
  49.     END SELECT
  50.     PRINT "          Number of Buttons:"; Buttons%
  51.     PRINT "                   IRQ Line:"; Irq%
  52.     PRINT
  53.     PRINT "Current mouse settings:"
  54.     PRINT
  55.     PRINT "           Horizontal Ratio:"; HorizRatio%; "mickeys per 8 pixels"
  56.     PRINT "             Vertical Ratio:"; VertRatio%; "mickeys per 8 pixels"
  57.     PRINT "     Double-speed Threshold:"; DblSpd%; "mickeys per second"
  58.     PRINT
  59.     PRINT "Press <Enter> to proceed to the next part of the demo or <Esc> to quit."
  60.  
  61.     CALL MousePointerOn                 'Makes the mouse pointer visible
  62.  
  63.     GOSUB WaitForEscOrEnter
  64.  
  65.     GOSUB ClearScreen
  66.     
  67.     PRINT
  68.     PRINT "You may now move the mouse around the screen. Press <P> to toggle"
  69.     PRINT "between Pixel and Row/Column coordinates. Press <Enter> to proceed"
  70.     PRINT "to the next part of the demo or press <Esc> to quit."
  71.     PRINT
  72.     
  73.     StartRow% = CSRLIN
  74.     PRINT "Mouse location (Vert/Horiz):"
  75.     PRINT "                Left Button:"
  76.     PRINT "               Right Button:"
  77.     IF Buttons% > 2 THEN
  78.         PRINT "              Center button:"
  79.     END IF
  80.  
  81.     CALL MousePointerOn                 'Makes the mouse pointer visible
  82.     
  83.     DO
  84.         A$ = INKEY$
  85.         SELECT CASE A$
  86.             CASE CHR$(27)                   'Esc
  87.                 GOTO MouseTestExit
  88.             CASE CHR$(13)                   'Enter
  89.                 EXIT DO
  90.             CASE "P", "p"
  91.                 Pixels% = Pixels% XOR -1
  92.                 IF Pixels% THEN
  93.                     CALL MousePixelsOn
  94.                 ELSE
  95.                     CALL MousePixelsOff
  96.                 END IF
  97.             CASE ELSE
  98.         END SELECT
  99.         CALL MouseGetStatus(Lb%, Rb%, Cb%, Row%, Column%)
  100.         LOCATE StartRow%, 29
  101.         PRINT STR$(Row%); ","; STR$(Column%); " (";
  102.         IF Pixels% THEN
  103.             PRINT "Pixels)      "
  104.         ELSE
  105.             PRINT "Row/Columns) "
  106.         END IF
  107.         LOCATE , 30
  108.         IF Lb% THEN
  109.             PRINT "Pressed    "
  110.         ELSE
  111.             PRINT "Not Pressed"
  112.         END IF
  113.         LOCATE , 30
  114.         IF Rb% THEN
  115.             PRINT "Pressed    "
  116.         ELSE
  117.             PRINT "Not Pressed"
  118.         END IF
  119.         IF Buttons% = 3 THEN
  120.             LOCATE , 30
  121.             IF Cb% THEN
  122.                 PRINT "Pressed    "
  123.             ELSE
  124.                 PRINT "Not Pressed"
  125.             END IF
  126.         END IF
  127.     LOOP
  128.     CALL MousePixelsOff                 'Back to row/column coordinates
  129.  
  130.     DEF SEG = 0
  131.     ScreenRows% = PEEK(&H484) + 1       'Get rows from EGA/VGA data area
  132.     IF ScreenRows% = 1 THEN             'If it was zero (we added one)
  133.         ScreenRows% = 25                'Then it must be a CGA/Mono - Only
  134.     END IF                              ' 25 rows are supported.
  135.     ScreenCols% = PEEK(&H44A)           'Get Screen columns from BIOS data area
  136.     DEF SEG
  137.  
  138.     GOSUB ClearScreen
  139.     
  140.     PRINT "You can now use the arrow keys position the mouse pointer. The"
  141.     PRINT "MouseSetPointer routine is being utilized for this purpose. Press"
  142.     PRINT "<Enter> when you are ready to proceed to the next part of the demo"
  143.     PRINT "or press <Esc> to quit."
  144.     CALL MousePointerOn
  145.     DO
  146.         DO
  147.             A$ = INKEY$
  148.         LOOP UNTIL LEN(A$)
  149.         
  150.         'In case you moved the mouse between key presses, Row% and Column%
  151.         CALL MouseGetStatus(Lb%, Rb%, Cb%, Row%, Column%)
  152.         
  153.         SELECT CASE A$
  154.             CASE CHR$(27)                   'Esc
  155.                 GOTO MouseTestExit
  156.             CASE CHR$(13)                   'Enter
  157.                 EXIT DO
  158.             CASE CHR$(0) + CHR$(72)         'Up arrow
  159.                 IF Row% > 1 THEN
  160.                     Row% = Row% - 1
  161.                 END IF
  162.             CASE CHR$(0) + CHR$(80)         'Down arrow
  163.                 IF Row% < ScreenRows% THEN
  164.                     Row% = Row% + 1
  165.                 END IF
  166.             CASE CHR$(0) + CHR$(75)         'Left arrow
  167.                 IF Column% > 1 THEN
  168.                     Column% = Column% - 1
  169.                 END IF
  170.             CASE CHR$(0) + CHR$(77)         'Right arrow
  171.                 IF Column% < ScreenCols% THEN
  172.                     Column% = Column% + 1
  173.                 END IF
  174.             CASE ELSE
  175.                 BEEP
  176.         END SELECT
  177.         CALL MouseSetPointer(Row%, Column%)
  178.     LOOP
  179.  
  180.     GOSUB ClearScreen
  181.  
  182.     PRINT "We can even tell you where a specific mouse button was pressed or"
  183.     PRINT "released, and how many times. For the next 10 seconds, move the"
  184.     PRINT "mouse around pressing and releasing the left button. At the end of"
  185.     PRINT "that time, we'll tell you how many times it was pressed and released,"
  186.     PRINT "and where the mouse pointer was located at the time of the last"
  187.     PRINT "press and release. Press <Enter> if you don't wish to wait a full 10 seconds."
  188.     PRINT
  189.  
  190.     Presses% = MousePressInfo(0, Row%, Column%)         'Resets the internal
  191.     Releases% = MouseReleaseInfo(0, Row%, Column%)      'counters.
  192.  
  193.     PRINT "Time left:";
  194.     CALL MousePointerOn
  195.     StartTime& = TIMER                          'Starting TIMER value
  196.     DO
  197.         TimeLeft% = 10& - (TIMER - StartTime&)  'Calculate time left
  198.         LOCATE , 11                             'Position cursor for display
  199.         PRINT TimeLeft%;                        'Print TimeLeft value
  200.         A$ = INKEY$                             'Check for a keypress
  201.     LOOP UNTIL TimeLeft% = 0 OR A$ = CHR$(13)   'Loop until Esc or out of time
  202.     PRINT
  203.     PRINT
  204.     PRINT "The left button was pressed"; MousePressInfo(0, Row%, Column%);
  205.     PRINT "times and was located at"; Row%; ","; Column%; "when it"
  206.     PRINT "was last pressed."
  207.     PRINT
  208.     PRINT "The left button was released"; MouseReleaseInfo(0, Row%, Column%);
  209.     PRINT "times and was located at"; Row%; ","; Column%; "when it"
  210.     PRINT "was last released."
  211.     PRINT
  212.     PRINT "Press <Enter> to proceed to the next part of the demo or press <Esc> to quit."
  213.     GOSUB WaitForEscOrEnter
  214.  
  215.     GOSUB ClearScreen
  216.     
  217.     PRINT "We'll now the use MouseSetWindow routine to restrict the movement of the"
  218.     PRINT "mouse pointer to a rectangular area of the screen. Press <Enter> to"
  219.     PRINT "proceed to the next part of the demo or press <Esc> to quit."
  220.     
  221.     LOCATE 5, 1
  222.     PRINT STRING$(1440, 219)            'Create a "blocked" area of the
  223.     FOR Row% = 8 TO 19                  ' screen. This helps to demonstrate
  224.         LOCATE Row%, 10                 ' the routine more effectively.
  225.         PRINT STRING$(60, " ");
  226.     NEXT
  227.  
  228.     CALL MousePointerOn                 'Pointer back on
  229.     CALL MouseSetWindow(8, 10, 19, 69)  'Define our window
  230.  
  231.     GOSUB WaitForEscOrEnter             'Hmm. What does this do?
  232.  
  233.     CALL MouseSetWindow(1, 1, ScreenRows%, ScreenCols%) 'Restore to whole scrn
  234.     
  235.     GOSUB ClearScreen
  236.     
  237.     PRINT "The MouseMovement routine can tell you how far the mouse has moved"
  238.     PRINT "between calls. The results are returned in "; mickeys; ". There are"
  239.     PRINT "about 200 mickeys per inch."
  240.     PRINT
  241.     PRINT "Each time you press the left mouse button, we'll show you how far the"
  242.     PRINT "mouse has moved since the last time the left button was pressed."
  243.     PRINT
  244.     PRINT "Press <Enter> when you are ready to proceed to the next part of the"
  245.     PRINT "demo or press <Esc> to quit."
  246.     PRINT
  247.     PRINT "Mouse movement since last left button click:"
  248.     PRINT
  249.     PRINT "     Horizontal Mickeys: 0"
  250.     PRINT "       Vertical Mickeys: 0"
  251.  
  252.     CALL MouseMovement(Rows%, Columns%)     'Reset the internal counters
  253.  
  254.     CALL MousePointerOn                     'So we can see it
  255.  
  256.     Rows% = 0                               'Zero our variables
  257.     Columns% = 0
  258.  
  259.     DO
  260.         
  261.         DO
  262.             CALL MouseGetStatus(Lb%, Rb%, Cb%, Row%, Column%)
  263.             A$ = INKEY$
  264.         LOOP UNTIL Lb% OR LEN(A$)
  265.         
  266.         IF Lb% THEN                                 'If left button pressed
  267.             CALL MouseMovement(Rows%, Columns%)     'How much has it moved?
  268.             LOCATE 13, 25
  269.             PRINT Rows%; "    "                     'Display the net changes
  270.             LOCATE , 25
  271.             PRINT Columns%; "    "
  272.             CALL MouseWaitForRelease                'Wait for button release
  273.         ELSE
  274.             SELECT CASE A$                          'A key was pressed
  275.                 CASE CHR$(27)                       'Esc
  276.                     GOTO MouseTestExit
  277.                 CASE CHR$(13)                       'Enter
  278.                     EXIT DO
  279.                 CASE ELSE                           'Whoops
  280.                     BEEP
  281.             END SELECT
  282.         END IF
  283.     LOOP
  284.  
  285.     GOSUB ClearScreen
  286.     
  287.     PRINT "Using the MouseSetRatio routine, you can control the sensitivity of the"
  288.     PRINT "mouse. It is used to adjust the ratio between the physical movement"
  289.     PRINT "of the mouse and the amount of movement reflected by the mouse pointer"
  290.     PRINT "on the screen."
  291.     PRINT
  292.     PRINT "The default setting is 8 mickeys per 8 pixels of horizontal movement"
  293.     PRINT "(1 mickey per pixel) and 16 mickeys per 8 pixels of vertical movement"
  294.     PRINT "(2 mickeys per pixel). In other words, the mouse is twice as sensitive to"
  295.     PRINT "horizontal movement than to vertical. This is necessary to more closely"
  296.     PRINT "match the proportions of your display."
  297.     PRINT
  298.     PRINT "We'll not make the mouse half as sensitive as it normally is. This means"
  299.     PRINT "that you'll have to move the mouse twice as far in order to move the"
  300.     PRINT "pointer the same distance. Try it now. Press <Enter> to proceed or press"
  301.     PRINT "<Esc> to quit."
  302.  
  303.     CALL MousePointerOn
  304.     CALL MouseSetRatio(32, 16)              'Make half as sensitive
  305.  
  306.     GOSUB WaitForEscOrEnter
  307.  
  308.     PRINT
  309.     PRINT "We'll now make the mouse twice as sensitive as it normally is. Try it now."
  310.     PRINT "Press <Enter> to proceed or <Esc> to quit."
  311.  
  312.     CALL MouseSetRatio(8, 4)                'Make twice as sensitive
  313.  
  314.     GOSUB WaitForEscOrEnter
  315.  
  316.     CALL MouseSetRatio(16, 8)               'Back to normal
  317.     
  318.     GOSUB ClearScreen
  319.     
  320.     PRINT "Using the MouseSetExclusionArea routine, you can define an area of the screen"
  321.     PRINT "that the mouse pointer will made invisible if moved into."
  322.     PRINT
  323.     PRINT "We've move the mouse cursor to the upper-left corner of the screen and"
  324.     PRINT "drawn a block below. If you move the mouse pointer into the block, the"
  325.     PRINT "pointer will disappear until you turn it back on again with the"
  326.     PRINT "MousePointerOn routine."
  327.     PRINT
  328.     PRINT "Press <Enter> to proceed to the next part of the demo or press <Esc> to quit."
  329.  
  330.     CALL MousePointerOn
  331.  
  332.     CALL MouseSetPointer(1, 1)
  333.  
  334.     CALL MouseSetExclusionArea(11, 10, 20, 70)
  335.  
  336.     FOR Row% = 11 TO 20
  337.         LOCATE Row%, 10
  338.         PRINT STRING$(61, 219)
  339.     NEXT
  340.     GOSUB WaitForEscOrEnter
  341.  
  342.     CALL MousePointerOn                 'Mouse exclusion turns it off
  343.     
  344.     GOSUB ClearScreen
  345.     
  346.     PRINT "MouseSaveState can be used to save the current mouse characteristics such"
  347.     PRINT "as locate, pointer definitions, visibility, etc., so it can be restored"
  348.     PRINT "at a later time with the MouseRestoreState routine."
  349.     PRINT
  350.     PRINT "The current mouse state has just been saved. Move the mouse around the"
  351.     PRINT "screen. When you press <Enter>, the mouse state will be restored. You can"
  352.     PRINT "tell it worked correctly if the mouse pointer is returned to its current"
  353.     PRINT "locate. Press <Esc> to quit."
  354.  
  355.     CALL MousePointerOn
  356.  
  357.     Success% = MouseSaveState%
  358.     IF NOT Success% THEN
  359.         PRINT
  360.         PRINT "Insufficient memory to save mouse state ... Press a key"
  361.     ELSE
  362.         GOSUB WaitForEscOrEnter
  363.  
  364.         CALL MouseRestoreState
  365.         PRINT
  366.         PRINT "The mouse state has been restored. Press <Enter> to proceed to the next"
  367.         PRINT "part of the demo or press <Esc> to quit."
  368.     END IF
  369.  
  370.     GOSUB WaitForEscOrEnter
  371.     
  372.     GOSUB ClearScreen
  373.  
  374.     PRINT "Using the MouseSetEvent routine in conjunction with BASIC's built-in"
  375.     PRINT "'ON UEVENT' function, we can build a mouse oriented event trap. BASIC"
  376.     PRINT "already has one for a joystick, the timer, the keyboard, etc., so why not"
  377.     PRINT "a mouse?? Only Microsoft knows for sure."
  378.     PRINT
  379.     PRINT "A mouse event has been set up. It will be triggered when the left button"
  380.     PRINT "is pressed, the right button is released, or when there is ANY mouse movement."
  381.     PRINT "Other options are available, but these are the only ones we'll demonstrate at"
  382.     PRINT "this time"
  383.     PRINT
  384.     PRINT "You'll see a message at the bottom of the screen each time an event occurs."
  385.     PRINT "You can try it now by moving the mouse around and pressing/releasing the"
  386.     PRINT "left and right mouse buttons."
  387.     PRINT
  388.     PRINT "Press any key when you've seen enough."
  389.     PRINT STRING$(79, "=")
  390.     VIEW PRINT 17 TO 25
  391.     
  392.     CALL MousePointerOn                     'Turn on mouse pointer
  393.     
  394.     CALL MouseSetEvent(19)                  '2 + 16
  395.  
  396.     ON UEVENT GOSUB MouseEventHandler       'Point to an event hander
  397.     UEVENT ON                               'Turn on event trapping.
  398.     
  399.     DO
  400.         A$ = INKEY$                         'Wait for a key
  401. EventCheckLabel:                            '/W will cause check for events here
  402.     LOOP UNTIL LEN(A$)
  403.  
  404.     UEVENT OFF                              'Turn off event trapping
  405.  
  406.     CALL MouseCancelEvent                   'Turn our handler off.
  407.     
  408.     VIEW PRINT                              'Back to normal
  409.     GOSUB ClearScreen
  410.     
  411.     PRINT "There are also some miscellaneous routines that do things like:"
  412.     PRINT
  413.     PRINT "  *  Change the mouse pointer's active display page"
  414.     PRINT "  *  Change the pointer's display characteristics"
  415.     PRINT "  *  Halt program execution until all buttons have been released"
  416.     PRINT "  *  Switch easily between row/column and pixel based coordinates"
  417.     PRINT
  418.     PRINT "The routines are extremely easy to use and 'forgiving'. For example: If you"
  419.     PRINT "save the current mouse state, memory is allocated to hold the data. If you"
  420.     PRINT "forget to call the MouseRestoreState routine, the memory will be released"
  421.     PRINT "automatically when your program terminates! Also, if you used the"
  422.     PRINT "MouseSetEvent routine and forget to call the MouseCancelEvent routine to"
  423.     PRINT "'unhook' your program from the mouse event chain, it'll be taken care of"
  424.     PRINT "for you automatically when you program ends."
  425.     PRINT
  426.     PRINT "If you have any additional ideas, comments, criticisms or suggestions,"
  427.     PRINT "please leave me a note on Compuserve - 76220,2575."
  428.     PRINT
  429.     PRINT "Thanks!   ----- Tony Elliott"
  430.     
  431. MouseTestExit:
  432.     CALL MousePointerOff
  433.     END
  434.  
  435. ClearScreen:
  436.     CALL MousePointerOff                'The cls overwrites the mouse pointer.
  437.     CLS                                 'So we have to turn it off, and CLS.
  438. RETURN                                  'We'll turn it back on again above
  439.  
  440. WaitForEscOrEnter:
  441.     DO
  442.         A$ = INKEY$
  443.     LOOP UNTIL A$ = CHR$(13) OR A$ = CHR$(27)
  444.     IF A$ = CHR$(27) THEN
  445.         RETURN MouseTestExit
  446.     END IF
  447. RETURN
  448.  
  449. MouseEventHandler:
  450.     'This subroutine used in conjunction with the MouseSetEvent and UEVENT
  451.     'demonstration.
  452.     
  453.     CALL MouseGetEventInfo(EventFlag%, Lb%, Rb%, Cb%, Row%, Column%)
  454.     CALL MousePointerOff                'To prevent mouse droppings
  455.     PRINT "Mouse Event - ";
  456.     IF EventFlag% AND 1 THEN            'We have to use multiple IF..THEN
  457.         PRINT "Mouse Motion - ";        ' blocks here instead of a SELECT CASE
  458.     END IF                              ' because it is possible for more than
  459.     IF EventFlag% AND 2 THEN            ' one type of event to occur
  460.         PRINT "Lb Pressed - ";          ' simultaneously.
  461.     END IF
  462.     IF EventFlag% AND 16 THEN           'If you are interested only in one
  463.         PRINT "Rb Released -";          ' type of event at a time, then a
  464.     END IF                              ' SELECT CASE structure would be more
  465.     PRINT Row%; ","; Column%            ' appropriate.
  466.     CALL MousePointerOn                 'Back on
  467. RETURN
  468.  
  469.  
  470.